from rest_framework import exceptions
from apitest.models import UserInfo, UserToken
from rest_framework.authentication import BaseAuthentication


class FirstAuthentication(BaseAuthentication):
    def authenticate(self,request):
        pass
    def authenticate_header(self, request):
        pass

class Authentication(BaseAuthentication):
    def authenticate(self,request):
        token = request._request.GET.get('token')
        print(token)
        token_obj = UserToken.objects.filter(Token=token).first()
        if not token_obj:
            raise exceptions.AuthenticationFailed('用户认证失败')
        return (token_obj.user,token_obj)
    def authenticate_header(self, request):
        pass